package tv.youxing.android.ui;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import tv.youxing.android.AboutUsActivity;
import tv.youxing.android.Interface.CustomToobarImp;
import tv.youxing.android.R;
import tv.youxing.android.custom.CustomToolbar;
import tv.youxing.android.utils.AppConst;
import tv.youxing.android.utils.ShareUtils;
import tv.youxing.android.utils.UtilTools;

public class SettingsActivity extends BaseActivity {

    @BindView(R.id.ll_myinfo_edit)
    RelativeLayout llMyInfoEdit;
    @BindView(R.id.ll_push_settings)
    RelativeLayout llPushSettings;
    @BindView(R.id.tingtongplay)
    CheckBox tingtongplay;
    @BindView(R.id.wifiautodownload)
    CheckBox wifiautodownload;
    @BindView(R.id.ll_clert)
    RelativeLayout llClert;
    @BindView(R.id.ll_guanyumy)
    RelativeLayout llGuanyumy;
    @BindView(R.id.cachesize)
    TextView tv_cachesize;//缓存大小
    @BindView(R.id.exit)
    Button btn_exit;//退出登录



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        ButterKnife.bind(this);


        CustomToolbar toolbar = (CustomToolbar) findViewById(R.id.tb);
        toolbar.setBackClickLister(new CustomToobarImp.back() {
            @Override
            public void onclick() {
                finish();
            }
        });

        initData();
    }

    void initData() {

        //听筒播放
        tingtongplay.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    //被选中
                }
            }
        });

        //WIFI状态下自动更新
        wifiautodownload.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {

            }
        });


        //清除缓存
        try {
            tv_cachesize.setText(UtilTools.getTotalCacheSize(this));

        } catch (Exception e) {
            e.printStackTrace();
        }


    }


    @OnClick({R.id.ll_myinfo_edit,R.id.ll_push_settings,R.id.ll_clert,R.id.ll_guanyumy,R.id.exit})
    public void click(View view) {

        switch (view.getId()) {
            case R.id.ll_myinfo_edit:

                startActivity(new Intent(this,MyInfoEditActivity.class));

                break;
            case R.id.ll_push_settings:

                startActivity(new Intent(this,PushSettingsActivity.class));

                break;
            case R.id.ll_clert:
                clert_Show();
                break;
            case R.id.ll_guanyumy:
                startActivity(new Intent(this, AboutUsActivity.class));
                break;
            case R.id.exit:
                startActivity(new Intent(this,LoginActivity.class));
                ShareUtils.putBoolean(this, AppConst.ISLOGIN,false);
                finish();
                break;
        }

    }

    //清除缓存的dialog
    void clert_Show() {
        android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(this);
        builder.setTitle("清除缓存");
        builder.setMessage("根据缓存的大小，清理从几秒到几分钟不等,请耐心等待.");
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                UtilTools.clearAllCache(SettingsActivity.this);
                tv_cachesize.setText("0M");
            }
        });
        builder.show();
    }
}
